import { reactive } from 'vue'

export default function () {
  let state = reactive({
    id: "",
    name: "",
    age: "",
    list: [
      {
        id: 1,
        name: "张三",
        age: 18,
      },
      {
        id: 2,
        name: "李四",
        age: 24,
      },
      {
        id: 3,
        name: "王五",
        age: 60,
      },
    ],
  });

  const remove = (index) => {
    state.list.splice(index, 1);
  };

  const addItem = () => {
    let item = {
      id: state.id,
      name: state.name,
      age: state.age,
    };

    state.list.push(item);

    state.id = "";
    state.name = "";
    state.age = "";
  };

  return {
    state,
    remove,
    addItem
  }
}

